﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessLogic
{
    public static class InstrumentTypeDataAccess
    {
        #region Methods
        public static InstrumentType BindDataToInstrumentType(DataRow row)
        {
            return CodeTableDataAccess.BindRowToCodeTable<InstrumentType>(row);
        }

        public static Guid Create(InstrumentType instrumentType)
        {
            Guid id = Guid.Empty;

            if (instrumentType != null)
            {
                id = CodeTableDataAccess.Create<InstrumentType>(StoredProcedures.USP_INSTRUMENTTYPECODE_CREATE, instrumentType.Description);
            }

            return id;
        }

        public static void Delete(InstrumentType instrumentType)
        {
            Delete(instrumentType.ID);
        }

        public static void Delete(Guid id)
        {
            List<Exception> exes = CodeTableDataAccess.Delete<InstrumentType>(StoredProcedures.USP_INSTRUMENTTYPECODE_DELETE, id);

            if (exes != null && exes.Count > 0)
            {
                throw exes[0];
            }
        }

        public static DataTable GetAll()
        {
            return CodeTableDataAccess.GetAll(StoredProcedures.USP_INSTRUMENTTYPECODE_GETALL);
        }

        public static DataRow GetByID(Guid id)
        {
            return CodeTableDataAccess.GetByID(StoredProcedures.USP_INSTRUMENTTYPECODE_GETBYID, id);
        }

        public static void Update(InstrumentType instrumentType)
        {
            if (instrumentType != null)
            {
                CodeTableDataAccess.Update<InstrumentType>(StoredProcedures.USP_INSTRUMENTTYPECODE_UPDATE, instrumentType.ID, instrumentType.Description);
            }
        }
        #endregion
    }
}